package views.text
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	
	public class MultiplePageTextView extends Sprite
	{
		private var _text:String;
		private var exampleTextArea:TextField;
		
		public function MultiplePageTextView()
		{
			exampleTextArea = getChildByName("txtExample") as TextField;
		}
		
		public function set text(_text:String):void
		{
			this._text = _text;
			
			while(numChildren > 0)
				removeChildAt(0);
			
			var txtX:Number = 0;
			var inputTxt:String = text;
			var txtPage:TextField;
			do
			{
				txtPage = new TextField;
				
				txtPage.width = exampleTextArea.width;
				txtPage.height = exampleTextArea.height;
				txtPage.multiline = true;
				txtPage.wordWrap = true;
				txtPage.selectable = exampleTextArea.selectable;
				
				txtPage.embedFonts = exampleTextArea.embedFonts;
				txtPage.text = inputTxt;
				txtPage.setTextFormat(exampleTextArea.getTextFormat());
				
				if(txtPage.bottomScrollV == txtPage.numLines)
				{
					inputTxt = "";
				}else{
					inputTxt = inputTxt.slice(txtPage.getLineOffset(txtPage.bottomScrollV),inputTxt.length);
					txtPage.text = txtPage.text.slice(0,txtPage.getLineOffset(txtPage.bottomScrollV));
					txtPage.setTextFormat(exampleTextArea.getTextFormat());
				}
				
				txtPage.x = txtX;
				txtPage.y = exampleTextArea.y;
				addChild(txtPage);
				
				txtX += txtPage.width;
			}while(inputTxt.length > 0)
		}
		
		public function get text():String
		{
			return _text;
		}
		
	}
}